//
//  YTStashRightTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/5.
//

#import "YTStashRightTableViewCell.h"
@interface YTStashRightTableViewCell ()

@property (nonatomic ,strong) UIImageView * img;
@property (nonatomic ,strong) UIView * line;
@property (nonatomic ,strong) UIView * makeview;
@property (nonatomic ,strong) UILabel * namelab;
@property (nonatomic ,strong) UILabel * contentlab;
@property (nonatomic ,strong) UILabel * kclab;
@property (nonatomic ,strong) UIButton * crkBtn;

@end
@implementation YTStashRightTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    
    UIView * makeview = [UIView new];
    self.makeview = makeview;
    makeview.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:makeview];
    [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.offset(0);
    }];
    
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#DBDBDB");
    self.line = line;
    [makeview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(0);
        make.left.offset(kwt(18));
        make.height.offset(0.5);
        make.right.offset(kwt(-13));
    }];
    
    
    UIImageView * img = kimageView(@"tangkou_photo");
    self.img = img;
    [makeview addSubview:img];
    [DTKTool YJ:kwt(4) andView:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(13));
        make.width.height.offset(kwt(66));
        make.top.offset(kwt(15));
    }];
    
    UILabel * namelab = [DTKTool labelWithText:@"--" andFont:kCFont(16) andTextColor:KcolorHex(@"#222222")];
    self.namelab = namelab;
    namelab.numberOfLines = 2;
    [makeview addSubview:namelab];
    [namelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(92));
        make.width.offset(kwt(180));
        make.top.offset(kwt(15));
    }];
    
    UILabel * temp = [DTKTool labelWithText:@"规格/单位:" andFont:kFont(14) andTextColor:KcolorHex(@"#787A79")];
    [makeview addSubview:temp];
    [temp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(92));
        make.top.equalTo(namelab.mas_bottom).offset(kwt(10));
    }];
    
    UILabel * contentlab = [DTKTool labelWithText:@"--" andFont:kFont(14) andTextColor:KcolorHex(@"#787A79")];
    self.contentlab = contentlab;
    [makeview addSubview:contentlab];
    [contentlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(temp.mas_right).offset(kwt(4));
        make.top.equalTo(temp);
    }];
    
    
    UILabel * kclab = [DTKTool labelWithText:@"--" andFont:kFont(14) andTextColor:KcolorHex(@"#F9491C")];
    self.kclab = kclab;
    [makeview addSubview:kclab];
    [kclab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(92));
        make.width.offset(kwt(110));
        make.top.equalTo(contentlab.mas_bottom).offset(kwt(10));
    }];
    
    UIButton * crkBtn = [UIButton buttonWithType:0];
    self.crkBtn = crkBtn;
    crkBtn.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(72), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#427FFF") endColor:KcolorHex(@"#3D5FFF")];
    crkBtn.addFont(kCFont(15)).addNormalColor(UIColor.whiteColor).addNormalText(@"出入库");
    crkBtn.addTarget(self,@selector(bcrBtnClick));
    [DTKTool YJ:kwt(15) andView:crkBtn];
    [makeview addSubview:crkBtn];
    [crkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-12));
        make.width.offset(kwt(72));
        make.height.offset(kwt(30));
        make.centerY.equalTo(kclab);
    }];
    
}

- (void)bcrBtnClick{
    if([UserInfoModel shared].userIdentity == 1){
        if(self.crkBlock){
            self.crkBlock(self.model);
        }
    } else if([UserInfoModel shared].userIdentity == 3){
        if(self.ckBlock){
            self.ckBlock(self.model);
        }
    }
}

- (void)setModel:(YTStashListModel *)model{
    _model = model;
    [self.img LZsetImageWithImagePath:model.productImg placeholderImage:[UIImage imageNamed:@"tangkou_photo"]];
    self.namelab.text = model.name;
    [self.namelab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.nameH);
    }];
    self.contentlab.text = [NSString stringWithFormat:@"%@/%@",model.productNorms,model.normsName];
    if(model.stockNumber < model.lowerLimit){
        self.kclab.text = @"库存不足";
    } else {
        self.kclab.text =  [NSString stringWithFormat:@"库存:%ld",(long)model.stockNumber];
    }
    if([UserInfoModel shared].userIdentity == 1){
        self.crkBtn.addNormalText(@"出入库");
    } else if([UserInfoModel shared].userIdentity == 3){
        self.crkBtn.addNormalText(@"出库");
    }
}
@end
